package com.maikec;
/**
 * 邢帅教育
 * <p>
 * 本源代码由数据中心及其作者共同所有，未经版权持有者的事先书面授权，
 * 不得使用、复制、修改、合并、发布、分发和/或销售本源代码的副本。
 *
 * @copyright Copyright (c) 2018. xsteach.com all rights reserved.
 */

import com.maikec.author.Author;
import com.maikec.author.AuthorMapper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.io.Reader;

/**
 * @author maikec
 * @date 2018/9/29
 */
public class MyBatisApplication {
    private static final Logger logger = LogManager.getLogger(MyBatisApplication.class.getName());
    public static void main(String[] args) throws Exception {
        int begin = 1;
        for ( ; begin < 100; begin++){

            logger.debug( "debug...");
            logger.info( "info..." );
            logger.error( "error..." );

            Reader reader = Resources.getResourceAsReader( "mybatisConfig.xml" );
            SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build( reader );
            AuthorMapper authorMapper = sqlSessionFactory.openSession(true).getMapper( AuthorMapper.class );
            Author author = new Author();
            author.setId( 103 );
            author.setUsername( "maikec" );
            author.setPassword( "123456" );
            author.setEmail( "maikec@126.com" );
            author.setBio( "maikec test" );

            authorMapper.insertAuthor( author );

            Thread.sleep( 3000 );
        }
    }
}
